///*
// *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
// *
// *  Redistribution and use in source and binary forms, with or without
// *  modification, are permitted provided that the following conditions are met:
// *
// *  Redistributions of source code must retain the above copyright notice,
// *  this list of conditions and the following disclaimer.
// *  Redistributions in binary form must reproduce the above copyright
// *  notice, this list of conditions and the following disclaimer in the
// *  documentation and/or other materials provided with the distribution.
// *  Neither the name of the dreamlu.net developer nor the names of its
// *  contributors may be used to endorse or promote products derived from
// *  this software without specific prior written permission.
// *  Author: Chill 庄骞 (smallchill@163.com)
// */
//package com.plian.system.service.dp.impl;
//
//import com.alibaba.fastjson.JSONObject;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.plian.Tools.*;
//import com.plian.Tools.pagedata.PageData;
//import com.plian.system.constant.sys.FormStatusConstant;
//import com.plian.system.constant.sys.FormTypeConstant;
//import com.plian.system.entity.dp.InvestigateCentralCommittee;
//import com.plian.system.mapper.dp.InvestigateCentralCommitteeMapper;
//import com.plian.system.mybatis.base.BaseFlowService;
//import com.plian.system.mybatis.base.BaseServiceImpl;
//import com.plian.system.mybatis.search.SearchEntity;
//import com.plian.system.mybatis.search.SearchParamEntiy;
//import com.plian.system.mybatis.support.Condition;
//import com.plian.system.pdf.OutPdf;
//import com.plian.system.service.dp.IInvestigateCentralCommitteeService;
//import com.plian.system.service.sys.code.IFormCodeService;
//import com.plian.system.service.wf.FormWorkflowService;
//import com.plian.system.vo.dp.InvestigateCentralCommitteeVO;
//import com.plian.system.wrapper.dp.InvestigateCentralCommitteeWrapper;
//import lombok.AllArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.io.FileUtils;
//import org.apache.commons.io.IOUtils;
//import org.apache.commons.lang.exception.ExceptionUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//
//import java.io.File;
//import java.io.InputStream;
//import java.util.*;
//
//import static com.plian.system.constant.sys.FormStatusConstant.UNREVIEWED;
//
///**
// * 查处违反中央八项规定精神问题情况 服务实现类
// *
// * @author jianglei
// * @since 2019-12-04
// */
//@Slf4j
//@Service
//@AllArgsConstructor
//public class InvestigateCentralCommitteeServiceImpl extends BaseServiceImpl<InvestigateCentralCommitteeMapper, InvestigateCentralCommittee> implements IInvestigateCentralCommitteeService, BaseFlowService {
//
//	private FormWorkflowService formWorkflowService;
//
//	private IFormCodeService formCodeService;
//
//	private InvestigateCentralCommitteeWrapper investigateCentralCommitteeWrapper;
//
//	@Override
//	@Transactional(rollbackFor=RuntimeException.class)
//	public boolean saveOrUpdate(InvestigateCentralCommittee investigateCentralCommittee) {
//		if (investigateCentralCommittee.getId() == null) {
//			investigateCentralCommittee.setCode(formCodeService.getCode(FormTypeConstant.DP_INVESTIGATE_CENTRAL_COMMITTEE_FORM));
//			investigateCentralCommittee.setFormType(String.valueOf(FormTypeConstant.DP_INVESTIGATE_CENTRAL_COMMITTEE_FORM));
//			investigateCentralCommittee.setVersion("1");
//		}
//		if (!Optional.ofNullable(investigateCentralCommittee.getStatus()).isPresent()) {
//			investigateCentralCommittee.setStatus(FormStatusConstant.UNREVIEWED);
//		}
//		return super.saveOrUpdate(investigateCentralCommittee);
//	}
//
//	@Override
//	@Transactional(rollbackFor=RuntimeException.class)
//	public boolean deleteLogic(List<Long> ids) {
//		for (Long id : ids) {
//			InvestigateCentralCommittee investigateCentralCommittee = getById(id);
//			if (investigateCentralCommittee == null) {
//				return false;
//			} else if (investigateCentralCommittee.getStatus() != null &&
//					(investigateCentralCommittee.getStatus() != FormStatusConstant.STASH && investigateCentralCommittee.getStatus() != FormStatusConstant.UNREVIEWED)) {
//				return false;
//			}
//			formWorkflowService.deleteProcessInstance(String.valueOf(id));
//		}
//		return super.deleteLogic(ids);
//	}
//
//	@Override
//	public File exportExcel(JSONObject jsonObject) {
//		List<SearchEntity> entityList = Optional.ofNullable(jsonObject.getJSONArray("query"))
//			.map(x -> x.toJavaList(SearchEntity.class)).orElse(new ArrayList<>());
//		QueryWrapper<InvestigateCentralCommittee> qw = SearchParamEntiy.getQueryWrapper(
//			Condition.getQueryWrapper(new InvestigateCentralCommittee()), entityList
//		);
//
//		List<InvestigateCentralCommittee> floors = list(qw);
////		return ExcelUtils.exportExcelByList(jsonObject, InvestigateCentralCommitteeWrapper.build().listVO(floors));
//		return null;
//	}
//
//	@Override
//	public HashMap<String,Object> commit(String id) {
//		handleStatus(Long.valueOf(id), FormStatusConstant.FLOW);
//
//		//将需要提交的流程变量返回，用于工作流侧
//		return new HashMap<String,Object>();
//	}
//
//	@Override
//	public Boolean finish(String id) {
//		return handleStatus(Long.valueOf(id), FormStatusConstant.FINISH);
//	}
//
//	@Override
//	public Boolean reject(String id, int formState, String comment) {
//		return handleStatus(Long.valueOf(id), formState);
//	}
//
//	@Override
//	public File buildPdf(Long id) {
//		InvestigateCentralCommitteeVO bean = investigateCentralCommitteeWrapper.entityToVO(getById(id));
//		File file = null;
//		try {
//			InputStream inputStream = this.getClass().getResourceAsStream("/pdf/investigateCentralCommittee.pdf");
//			//通过将文件转换为临时文件进行操作
//			File model = File.createTempFile("model", ".png");
//			try {
//				FileUtils.copyInputStreamToFile(inputStream, model);
//			} finally {
//				//关闭IO
//				IOUtils.closeQuietly(inputStream);
//			}
//			if (bean != null && model.exists()) {
//				Map<String, Object> data = new HashMap<>(16);
//				data.put("fillingUnitName", bean.getFillingUnitName());
//				if (Optional.ofNullable(bean.getFillingDate()).isPresent()) {
//					data.put("fillingDate", DateUtil.format(bean.getFillingDate(), "yyyy年M月"));
//				}
//				data.put("offenderName", bean.getOffenderName());
//				data.put("gender", bean.getGenderName());
//				data.put("rankName", bean.getRankName());
//				data.put("companyAndJob", bean.getCompanyAndJob());
//				data.put("problemsType", bean.getProblemsType());
//				data.put("violationOccurredDate", DateUtil.formatDate(bean.getViolationOccurredDate()));
//				data.put("partyDisciplineName", bean.getPartyDisciplineName());
//				if (Optional.ofNullable(bean.getPartyDisciplineTime()).isPresent()){
//					data.put("partyDisciplineTime", DateUtil.formatDate(bean.getPartyDisciplineTime()));
//				}
//				data.put("partyDecisionAuthority", bean.getPartyDecisionAuthority());
//				data.put("disciplinarySanctionsName", bean.getDisciplinarySanctionsName());
//				if (Optional.ofNullable(bean.getDisciplinarySanctionsTime()).isPresent()) {
//					data.put("disciplinarySanctionsTime", DateUtil.formatDate(bean.getDisciplinarySanctionsTime()));
//				}
//				data.put("disciplinaryDecisionAuthority", bean.getDisciplinaryDecisionAuthority());
//				data.put("tissueManagementName", bean.getTissueManagementName());
//				if (Optional.ofNullable(bean.getTissueManagementTime()).isPresent()) {
//					data.put("tissueManagementTime", DateUtil.formatDate(bean.getTissueManagementTime()));
//				}
//				data.put("tissueDecisionAuthority", bean.getTissueDecisionAuthority());
//				data.put("mainProblemPlot", bean.getMainProblemPlot());
//				file = OutPdf.createPdf(model, data, bean.getClass().getName());
//			}
//
//		} catch (Exception e) {
//			log.error(ExceptionUtils.getFullStackTrace(e));
//		}
//		return file;
//	}
//
//	@Override
//	public List<PageData> findByIds(List<String> formIds) {
//		QueryWrapper<InvestigateCentralCommittee> queryWrapper = new QueryWrapper<>();
//		queryWrapper.in("id", Func.toLongList(StringUtils.join(formIds, StringPool.COMMA)));
//		List<InvestigateCentralCommittee> investigateCentralCommittees = list(queryWrapper);
//		List<InvestigateCentralCommitteeVO> investigateCentralCommitteeVOS = investigateCentralCommitteeWrapper.entityToVO(investigateCentralCommittees);
//		List<PageData> pageDataList = new ArrayList<>();
//		try{
//			if (CollectionUtil.isNotEmpty(investigateCentralCommitteeVOS)){
//				for (InvestigateCentralCommitteeVO vo : investigateCentralCommitteeVOS){
//					PageData pd = new PageData();
//					pd.put("id", vo.getId());
//					pd.put("UNITNAME", vo.getFillingUnitName());
//					pd.put("APPLICANTNAME", vo.getCreateUserName());
//					pd.put("applicantId", vo.getCreateUser());
//					pd.put("applyOrganizationId", vo.getFillingUnitId());
//					pd.put("formType", FormTypeConstant.DP_INVESTIGATE_CENTRAL_COMMITTEE_FORM);
//					pd.put("orgName", vo.getFillingUnitName());
//					pageDataList.add(pd);
//				}
//			}
//
//			return pageDataList;
//		} catch (Exception e) {
//			log.error(ExceptionUtils.getFullStackTrace(e));
//		}
//		return pageDataList;
//	}
//
//	@Override
//	public List<Integer> getFormType() {
//		return Arrays.asList(FormTypeConstant.DP_INVESTIGATE_CENTRAL_COMMITTEE_FORM);
//	}
//
//	@Override
//	public void goBackToStash(String formId) {
//		handleStatus(Long.valueOf(formId), UNREVIEWED);
//	}
//
//	/**
//	 * 统一处理状态机事件方法
//	 *
//	 * @param id          主键
//	 * @param updateStatus  更新状态
//	 * @return boolean
//	 */
//	private Boolean handleStatus(Long id, int updateStatus) {
//		try {
//			InvestigateCentralCommittee investigateCentralCommittee = getById(id);
//			/**
//			 * 设置审批人和审批时间
//			 */
//			if (updateStatus == FormStatusConstant.FINISH){
//				investigateCentralCommittee.setApprovedUser(TokenUtil.getTokenUserId());
//				Date now = DateUtil.now();
//				investigateCentralCommittee.setApprovedTime(now);
//			}
//			investigateCentralCommittee.setStatus(updateStatus);
//			updateById(investigateCentralCommittee);
//			return true;
//		} catch (Exception e) {
//			log.error(ExceptionUtils.getFullStackTrace(e));
//			return false;
//		}
//	}
//}
